package com.iengoo.spacewar;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author zpym
 * @CopyRight (C) http://www.iengoo.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-12-26 20:08
 */
public class Grid {
    private BufferedImage grid;
    public static final int WIDTH = 62;
    public static final int HEIGHT = 62;
    private double speed = 0.4;
    private double x;
    private double y;

    public Grid(double x, double y) throws IOException {
        grid = ImageIO.read(getClass().getResource("resources/grid.png"));
        this.x = x;
        this.y = y;
    }

    public void paint(Graphics g) {
        g.drawImage(grid, (int)x, (int)y, grid.getWidth(), grid.getHeight(),null);
    }

    public void move() {
        this.y += speed;
    }

    /**
     * 让GridImage y坐标回到第一个
     */
    public void toFirst() {
        this.y = - (Grid.HEIGHT * GridContainer.numY - Config.PANEL_HEIGHT + Grid.HEIGHT);
    }

    public double getY() {
        return y;
    }
}
